/**
 * Created by showtan on 2018/12/27.
 * Stack console.log(navigation.state.routeName) 如果是header右边是function 就用用监听
 */

import TabNav from './TabNav';
import TaskDetail from '../pages/home/TaskDetail';
import MessageDetail from '../pages/message/MessageDetail';
import TaskList from '../pages/mine/TaskList';
import UpdateInfo from '../pages/mine/UpdateInfo';
import AssignTask from '../pages/mine/AssignTask';
import MapTest from '../pages/mine/MapTest';
import LoginScreen from '../pages/login';
import RegisterScreen from '../pages/login/Register';

const StackOptions = ({ navigation }) => {
  const headerTitleStyle = { alignSelf: 'center', textAlign: 'center', flex: 1, color: '#333' };
  const headerTitle = navigation.state.params.title;
  const headerStyle = { backgroundColor: '#fff' };
  const headerLeft = <TouchableOpacity style={{ height: isIOS ? adapt(40) : adapt(50), width: adapt(50), justifyContent: 'center' }} activeOpacity={.5} onPress={() => navigation.goBack()}>
    <Image source={Images.common.icon_back} style={{ height: adapt(21), width: adapt(12), marginLeft: adapt(20), tintColor: '#717171' }} />
  </TouchableOpacity>;
  const headerRight = <View style={{ width: adapt(50) }} />;
  return { headerTitleStyle, headerTitle, headerStyle, headerRight, headerLeft }
}

const StackNav = createStackNavigator({
  TaskDetail: { screen: TaskDetail },
  MessageDetail: { screen: MessageDetail, navigationOptions: ({ navigation }) => StackOptions({ navigation }) },
  TaskList: { screen: TaskList, navigationOptions: ({ navigation }) => StackOptions({ navigation }) },
  UpdateInfo: { screen: UpdateInfo, navigationOptions: ({ navigation }) => StackOptions({ navigation }) },
  AssignTask: { screen: AssignTask, navigationOptions: ({ navigation }) => StackOptions({ navigation }) },
  MapTest: { screen: MapTest, navigationOptions: ({ navigation }) => StackOptions({ navigation }) },
  LoginScreen: { screen: LoginScreen, navigationOptions: ({ navigation }) => StackOptions({ navigation }) },
  RegisterScreen: { screen: RegisterScreen, navigationOptions: ({ navigation }) => StackOptions({ navigation }) },
  Main: {
    screen: TabNav,
    // navigationOptions: ({ navigation }) => ({
    //   headerTitle: navigation.state.index == 0 ? '任务列表' : navigation.state.index == 1 ? '消息通知' : '个人中心',
    //   headerTitleStyle: { color: '#fff', alignSelf: 'center', textAlign: 'center', flex: 1 },
    //   headerStyle: { backgroundColor: themeColor },
    //   headerBackTitle: navigation.state.index == 0 ? '任务列表' : navigation.state.index == 1 ? '消息通知' : '个人中心', // 返回title改变
    //   headerRight: navigation.state.index == 2 ? <TouchableOpacity onPress={() => navigation.navigate('AssignTask', {})} style={{ width: adapt(50), height: adapt(50), justifyContent: 'center', alignItems: 'center' }}>
    //     <Image source={Images.other.icon_add} style={{ width: adapt(30), height: adapt(30), tintColor: '#fff' }} />
    //   </TouchableOpacity> : <View style={{ width: adapt(50) }} />,
    //   headerLeft: <View style={{ width: adapt(50) }} />
    // })
    navigationOptions: ({ header: null })
  }
}, {
    defaultNavigationOptions: {
      animationEnabled: true, // 开启动画
      gesturesEnabled: true, // 开启边缘触摸返回
      headerTintColor: '#000', // 导航栏颜色
      headerBackTitle: '返回'
    },
    // initialRouteName: !YXStorage.get('isFirstLogin') ? 'GuideScreen' : 'Tab',
    initialRouteName: 'Main',
    mode: 'card'
  });

export default createAppContainer(StackNav);